﻿package org.flixel
{
    import flash.display.*;

    public class FlxObject extends FlxBasic
    {
        public var x:Number;
        public var y:Number;
        public var width:Number;
        public var height:Number;
        public var immovable:Boolean;
        public var velocity:FlxPoint;
        public var mass:Number;
        public var elasticity:Number;
        public var acceleration:FlxPoint;
        public var drag:FlxPoint;
        public var maxVelocity:FlxPoint;
        public var angle:Number;
        public var angularVelocity:Number;
        public var angularAcceleration:Number;
        public var angularDrag:Number;
        public var maxAngular:Number;
        public var scrollFactor:FlxPoint;
        protected var _flicker:Boolean;
        protected var _flickerTimer:Number;
        public var health:Number;
        protected var _point:FlxPoint;
        protected var _rect:FlxRect;
        public var moves:Boolean;
        public var touching:uint;
        public var wasTouching:uint;
        public var allowCollisions:uint;
        public var last:FlxPoint;
        public var path:FlxPath;
        public var pathSpeed:Number;
        public var pathAngle:Number;
        protected var _pathNodeIndex:int;
        protected var _pathMode:uint;
        protected var _pathInc:int;
        protected var _pathRotate:Boolean;
        public static const LEFT:uint = 1;
        public static const RIGHT:uint = 16;
        public static const UP:uint = 256;
        public static const DOWN:uint = 4096;
        public static const NONE:uint = 0;
        public static const CEILING:uint = 256;
        public static const FLOOR:uint = 4096;
        public static const WALL:uint = LEFT | RIGHT;
        public static const ANY:uint = LEFT | RIGHT | UP | DOWN;
        public static const OVERLAP_BIAS:Number = 4;
        public static const PATH_FORWARD:uint = 0;
        public static const PATH_BACKWARD:uint = 1;
        public static const PATH_LOOP_FORWARD:uint = 16;
        public static const PATH_LOOP_BACKWARD:uint = 256;
        public static const PATH_YOYO:uint = 4096;
        public static const PATH_HORIZONTAL_ONLY:uint = 65536;
        public static const PATH_VERTICAL_ONLY:uint = 1048576;
        static const _pZero:FlxPoint = new FlxPoint();

        public function FlxObject(param1:Number = 0, param2:Number = 0, param3:Number = 0, param4:Number = 0)
        {
            this.x = param1;
            this.y = param2;
            this.last = new FlxPoint(this.x, this.y);
            this.width = param3;
            this.height = param4;
            this.mass = 1;
            this.elasticity = 0;
            this.immovable = false;
            this.moves = true;
            this.touching = NONE;
            this.wasTouching = NONE;
            this.allowCollisions = ANY;
            this.velocity = new FlxPoint();
            this.acceleration = new FlxPoint();
            this.drag = new FlxPoint();
            this.maxVelocity = new FlxPoint(10000, 10000);
            this.angle = 0;
            this.angularVelocity = 0;
            this.angularAcceleration = 0;
            this.angularDrag = 0;
            this.maxAngular = 10000;
            this.scrollFactor = new FlxPoint(1, 1);
            this._flicker = false;
            this._flickerTimer = 0;
            this._point = new FlxPoint();
            this._rect = new FlxRect();
            this.path = null;
            this.pathSpeed = 0;
            this.pathAngle = 0;
            return;
        }// end function

        override public function destroy() : void
        {
            this.velocity = null;
            this.acceleration = null;
            this.drag = null;
            this.maxVelocity = null;
            this.scrollFactor = null;
            this._point = null;
            this._rect = null;
            this.last = null;
            cameras = null;
            if (this.path != null)
            {
                this.path.destroy();
            }
            this.path = null;
            return;
        }// end function

        override public function preUpdate() : void
        {
            var _loc_2:* = _ACTIVECOUNT + 1;
            _ACTIVECOUNT = _loc_2;
            if (this._flickerTimer != 0)
            {
                if (this._flickerTimer > 0)
                {
                    this._flickerTimer = this._flickerTimer - FlxG.elapsed;
                    if (this._flickerTimer <= 0)
                    {
                        this._flickerTimer = 0;
                        this._flicker = false;
                    }
                }
            }
            this.last.x = this.x;
            this.last.y = this.y;
            if (this.path != null && this.pathSpeed != 0 && this.path.nodes[this._pathNodeIndex] != null)
            {
                this.updatePathMotion();
            }
            return;
        }// end function

        override public function postUpdate() : void
        {
            if (this.moves)
            {
                this.updateMotion();
            }
            this.wasTouching = this.touching;
            this.touching = NONE;
            return;
        }// end function

        protected function updateMotion() : void
        {
            var _loc_1:Number = NaN;
            var _loc_2:Number = NaN;
            _loc_2 = (FlxU.computeVelocity(this.angularVelocity, this.angularAcceleration, this.angularDrag, this.maxAngular) - this.angularVelocity) / 2;
            this.angularVelocity = this.angularVelocity + _loc_2;
            this.angle = this.angle + this.angularVelocity * FlxG.elapsed;
            this.angularVelocity = this.angularVelocity + _loc_2;
            _loc_2 = (FlxU.computeVelocity(this.velocity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
            this.velocity.x = this.velocity.x + _loc_2;
            _loc_1 = this.velocity.x * FlxG.elapsed;
            this.velocity.x = this.velocity.x + _loc_2;
            this.x = this.x + _loc_1;
            _loc_2 = (FlxU.computeVelocity(this.velocity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
            this.velocity.y = this.velocity.y + _loc_2;
            _loc_1 = this.velocity.y * FlxG.elapsed;
            this.velocity.y = this.velocity.y + _loc_2;
            this.y = this.y + _loc_1;
            return;
        }// end function

        override public function draw() : void
        {
            var _loc_1:FlxCamera = null;
            if (cameras == null)
            {
                cameras = FlxG.cameras;
            }
            var _loc_2:uint = 0;
            var _loc_3:* = cameras.length;
            while (_loc_2 < _loc_3)
            {
                
                _loc_1 = cameras[_loc_2++];
                if (this.onScreen(_loc_1))
                {
                    var _loc_5:* = _VISIBLECOUNT + 1;
                    _VISIBLECOUNT = _loc_5;
                    if (FlxG.visualDebug && !ignoreDrawDebug)
                    {
                        this.drawDebug(_loc_1);
                    }
                }
            }
            return;
        }// end function

        override public function drawDebug(param1:FlxCamera = null) : void
        {
            var _loc_7:uint = 0;
            if (param1 == null)
            {
                param1 = FlxG.camera;
            }
            var _loc_2:* = this.x - int(param1.scroll.x * this.scrollFactor.x);
            var _loc_3:* = this.y - int(param1.scroll.y * this.scrollFactor.y);
            _loc_2 = int(_loc_2 + (_loc_2 > 0 ? (1e-007) : (-1e-007)));
            _loc_3 = int(_loc_3 + (_loc_3 > 0 ? (1e-007) : (-1e-007)));
            var _loc_4:* = this.width != int(this.width) ? (this.width) : ((this.width - 1));
            var _loc_5:* = this.height != int(this.height) ? (this.height) : ((this.height - 1));
            var _loc_6:* = FlxG.flashGfx;
            FlxG.flashGfx.clear();
            _loc_6.moveTo(_loc_2, _loc_3);
            if (this.allowCollisions)
            {
                if (this.allowCollisions != ANY)
                {
                    _loc_7 = FlxG.PINK;
                }
                if (this.immovable)
                {
                    _loc_7 = FlxG.GREEN;
                }
                else
                {
                    _loc_7 = FlxG.RED;
                }
            }
            else
            {
                _loc_7 = FlxG.BLUE;
            }
            _loc_6.lineStyle(1, _loc_7, 0.5);
            _loc_6.lineTo(_loc_2 + _loc_4, _loc_3);
            _loc_6.lineTo(_loc_2 + _loc_4, _loc_3 + _loc_5);
            _loc_6.lineTo(_loc_2, _loc_3 + _loc_5);
            _loc_6.lineTo(_loc_2, _loc_3);
            param1.buffer.draw(FlxG.flashGfxSprite);
            return;
        }// end function

        public function followPath(param1:FlxPath, param2:Number = 100, param3:uint = 0, param4:Boolean = false) : void
        {
            if (param1.nodes.length <= 0)
            {
                FlxG.log("WARNING: Paths need at least one node in them to be followed.");
                return;
            }
            this.path = param1;
            this.pathSpeed = FlxU.abs(param2);
            this._pathMode = param3;
            this._pathRotate = param4;
            if (this._pathMode == PATH_BACKWARD || this._pathMode == PATH_LOOP_BACKWARD)
            {
                this._pathNodeIndex = this.path.nodes.length - 1;
                this._pathInc = -1;
            }
            else
            {
                this._pathNodeIndex = 0;
                this._pathInc = 1;
            }
            return;
        }// end function

        public function stopFollowingPath(param1:Boolean = false) : void
        {
            this.pathSpeed = 0;
            if (param1 && this.path != null)
            {
                this.path.destroy();
                this.path = null;
            }
            return;
        }// end function

        protected function advancePath(param1:Boolean = true) : FlxPoint
        {
            var _loc_2:FlxPoint = null;
            if (param1)
            {
                _loc_2 = this.path.nodes[this._pathNodeIndex];
                if (_loc_2 != null)
                {
                    if ((this._pathMode & PATH_VERTICAL_ONLY) == 0)
                    {
                        this.x = _loc_2.x - this.width * 0.5;
                    }
                    if ((this._pathMode & PATH_HORIZONTAL_ONLY) == 0)
                    {
                        this.y = _loc_2.y - this.height * 0.5;
                    }
                }
            }
            this._pathNodeIndex = this._pathNodeIndex + this._pathInc;
            if ((this._pathMode & PATH_BACKWARD) > 0)
            {
                if (this._pathNodeIndex < 0)
                {
                    this._pathNodeIndex = 0;
                    this.pathSpeed = 0;
                }
            }
            else if ((this._pathMode & PATH_LOOP_FORWARD) > 0)
            {
                if (this._pathNodeIndex >= this.path.nodes.length)
                {
                    this._pathNodeIndex = 0;
                }
            }
            else if ((this._pathMode & PATH_LOOP_BACKWARD) > 0)
            {
                if (this._pathNodeIndex < 0)
                {
                    this._pathNodeIndex = this.path.nodes.length - 1;
                    if (this._pathNodeIndex < 0)
                    {
                        this._pathNodeIndex = 0;
                    }
                }
            }
            else if ((this._pathMode & PATH_YOYO) > 0)
            {
                if (this._pathInc > 0)
                {
                    if (this._pathNodeIndex >= this.path.nodes.length)
                    {
                        this._pathNodeIndex = this.path.nodes.length - 2;
                        if (this._pathNodeIndex < 0)
                        {
                            this._pathNodeIndex = 0;
                        }
                        this._pathInc = -this._pathInc;
                    }
                }
                else if (this._pathNodeIndex < 0)
                {
                    this._pathNodeIndex = 1;
                    if (this._pathNodeIndex >= this.path.nodes.length)
                    {
                        this._pathNodeIndex = this.path.nodes.length - 1;
                    }
                    if (this._pathNodeIndex < 0)
                    {
                        this._pathNodeIndex = 0;
                    }
                    this._pathInc = -this._pathInc;
                }
            }
            else if (this._pathNodeIndex >= this.path.nodes.length)
            {
                this._pathNodeIndex = this.path.nodes.length - 1;
                this.pathSpeed = 0;
            }
            return this.path.nodes[this._pathNodeIndex];
        }// end function

        protected function updatePathMotion() : void
        {
            this._point.x = this.x + this.width * 0.5;
            this._point.y = this.y + this.height * 0.5;
            var _loc_1:* = this.path.nodes[this._pathNodeIndex];
            var _loc_2:* = _loc_1.x - this._point.x;
            var _loc_3:* = _loc_1.y - this._point.y;
            var _loc_4:* = (this._pathMode & PATH_HORIZONTAL_ONLY) > 0;
            var _loc_5:* = (this._pathMode & PATH_VERTICAL_ONLY) > 0;
            if (_loc_4)
            {
                if ((_loc_2 > 0 ? (_loc_2) : (-_loc_2)) < this.pathSpeed * FlxG.elapsed)
                {
                    _loc_1 = this.advancePath();
                }
            }
            else if (_loc_5)
            {
                if ((_loc_3 > 0 ? (_loc_3) : (-_loc_3)) < this.pathSpeed * FlxG.elapsed)
                {
                    _loc_1 = this.advancePath();
                }
            }
            else if (Math.sqrt(_loc_2 * _loc_2 + _loc_3 * _loc_3) < this.pathSpeed * FlxG.elapsed)
            {
                _loc_1 = this.advancePath();
            }
            if (this.pathSpeed != 0)
            {
                this._point.x = this.x + this.width * 0.5;
                this._point.y = this.y + this.height * 0.5;
                if (_loc_4 || this._point.y == _loc_1.y)
                {
                    this.velocity.x = this._point.x < _loc_1.x ? (this.pathSpeed) : (-this.pathSpeed);
                    if (this.velocity.x < 0)
                    {
                        this.pathAngle = -90;
                    }
                    else
                    {
                        this.pathAngle = 90;
                    }
                    if (!_loc_4)
                    {
                        this.velocity.y = 0;
                    }
                }
                else if (_loc_5 || this._point.x == _loc_1.x)
                {
                    this.velocity.y = this._point.y < _loc_1.y ? (this.pathSpeed) : (-this.pathSpeed);
                    if (this.velocity.y < 0)
                    {
                        this.pathAngle = 0;
                    }
                    else
                    {
                        this.pathAngle = 180;
                    }
                    if (!_loc_5)
                    {
                        this.velocity.x = 0;
                    }
                }
                else
                {
                    this.pathAngle = FlxU.getAngle(this._point, _loc_1);
                    FlxU.rotatePoint(0, this.pathSpeed, 0, 0, this.pathAngle, this.velocity);
                }
                if (this._pathRotate)
                {
                    this.angularVelocity = 0;
                    this.angularAcceleration = 0;
                    this.angle = this.pathAngle;
                }
            }
            return;
        }// end function

        public function overlaps(param1:FlxBasic, param2:Boolean = false, param3:FlxCamera = null) : Boolean
        {
            var _loc_6:Boolean = false;
            var _loc_7:uint = 0;
            var _loc_8:FlxGroup = null;
            if (param1 is FlxGroup)
            {
                _loc_6 = false;
                _loc_7 = 0;
                _loc_8 = param1 as FlxGroup;
                while (_loc_7 < _loc_8.length)
                {
                    
                    if (this.overlaps(_loc_8.members[_loc_7++], param2, param3))
                    {
                        _loc_6 = true;
                    }
                }
                return _loc_6;
            }
            if (param1 is FlxTilemap)
            {
                return (param1 as FlxTilemap).overlaps(this, param2, param3);
            }
            var _loc_4:* = param1 as FlxObject;
            if (!param2)
            {
                return _loc_4.x + _loc_4.width > this.x && _loc_4.x < this.x + this.width && _loc_4.y + _loc_4.height > this.y && _loc_4.y < this.y + this.height;
            }
            if (param3 == null)
            {
                param3 = FlxG.camera;
            }
            var _loc_5:* = _loc_4.getScreenXY(null, param3);
            this.getScreenXY(this._point, param3);
            return _loc_5.x + _loc_4.width > this._point.x && _loc_5.x < this._point.x + this.width && _loc_5.y + _loc_4.height > this._point.y && _loc_5.y < this._point.y + this.height;
        }// end function

        public function overlapsAt(param1:Number, param2:Number, param3:FlxBasic, param4:Boolean = false, param5:FlxCamera = null) : Boolean
        {
            var _loc_8:Boolean = false;
            var _loc_9:FlxBasic = null;
            var _loc_10:uint = 0;
            var _loc_11:Array = null;
            var _loc_12:FlxTilemap = null;
            if (param3 is FlxGroup)
            {
                _loc_8 = false;
                _loc_10 = 0;
                _loc_11 = (param3 as FlxGroup).members;
                while (_loc_10 < length)
                {
                    
                    if (this.overlapsAt(param1, param2, _loc_11[_loc_10++], param4, param5))
                    {
                        _loc_8 = true;
                    }
                }
                return _loc_8;
            }
            if (param3 is FlxTilemap)
            {
                _loc_12 = param3 as FlxTilemap;
                return (param3 as FlxTilemap).overlapsAt(_loc_12.x - (param1 - this.x), _loc_12.y - (param2 - this.y), this, param4, param5);
            }
            var _loc_6:* = param3 as FlxObject;
            if (!param4)
            {
                return _loc_6.x + _loc_6.width > param1 && _loc_6.x < param1 + this.width && _loc_6.y + _loc_6.height > param2 && _loc_6.y < param2 + this.height;
            }
            if (param5 == null)
            {
                param5 = FlxG.camera;
            }
            var _loc_7:* = _loc_6.getScreenXY(null, param5);
            this._point.x = param1 - int(param5.scroll.x * this.scrollFactor.x);
            this._point.y = param2 - int(param5.scroll.y * this.scrollFactor.y);
            this._point.x = this._point.x + (this._point.x > 0 ? (1e-007) : (-1e-007));
            this._point.y = this._point.y + (this._point.y > 0 ? (1e-007) : (-1e-007));
            return _loc_7.x + _loc_6.width > this._point.x && _loc_7.x < this._point.x + this.width && _loc_7.y + _loc_6.height > this._point.y && _loc_7.y < this._point.y + this.height;
        }// end function

        public function overlapsPoint(param1:FlxPoint, param2:Boolean = false, param3:FlxCamera = null) : Boolean
        {
            if (!param2)
            {
                return param1.x > this.x && param1.x < this.x + this.width && param1.y > this.y && param1.y < this.y + this.height;
            }
            if (param3 == null)
            {
                param3 = FlxG.camera;
            }
            var _loc_4:* = param1.x - param3.scroll.x;
            var _loc_5:* = param1.y - param3.scroll.y;
            this.getScreenXY(this._point, param3);
            return _loc_4 > this._point.x && _loc_4 < this._point.x + this.width && _loc_5 > this._point.y && _loc_5 < this._point.y + this.height;
        }// end function

        public function onScreen(param1:FlxCamera = null) : Boolean
        {
            if (param1 == null)
            {
                param1 = FlxG.camera;
            }
            this.getScreenXY(this._point, param1);
            return this._point.x + this.width > 0 && this._point.x < param1.width && this._point.y + this.height > 0 && this._point.y < param1.height;
        }// end function

        public function getScreenXY(param1:FlxPoint = null, param2:FlxCamera = null) : FlxPoint
        {
            if (param1 == null)
            {
                param1 = new FlxPoint();
            }
            if (param2 == null)
            {
                param2 = FlxG.camera;
            }
            param1.x = this.x - int(param2.scroll.x * this.scrollFactor.x);
            param1.y = this.y - int(param2.scroll.y * this.scrollFactor.y);
            param1.x = param1.x + (param1.x > 0 ? (1e-007) : (-1e-007));
            param1.y = param1.y + (param1.y > 0 ? (1e-007) : (-1e-007));
            return param1;
        }// end function

        public function flicker(param1:Number = 1) : void
        {
            this._flickerTimer = param1;
            if (this._flickerTimer == 0)
            {
                this._flicker = false;
            }
            return;
        }// end function

        public function get flickering() : Boolean
        {
            return this._flickerTimer != 0;
        }// end function

        public function get solid() : Boolean
        {
            return (this.allowCollisions & ANY) > NONE;
        }// end function

        public function set solid(param1:Boolean) : void
        {
            if (param1)
            {
                this.allowCollisions = ANY;
            }
            else
            {
                this.allowCollisions = NONE;
            }
            return;
        }// end function

        public function getMidpoint(param1:FlxPoint = null) : FlxPoint
        {
            if (param1 == null)
            {
                param1 = new FlxPoint();
            }
            param1.x = this.x + this.width * 0.5;
            param1.y = this.y + this.height * 0.5;
            return param1;
        }// end function

        public function reset(param1:Number, param2:Number) : void
        {
            revive();
            this.touching = NONE;
            this.wasTouching = NONE;
            this.x = param1;
            this.y = param2;
            this.last.x = this.x;
            this.last.y = this.y;
            this.velocity.x = 0;
            this.velocity.y = 0;
            return;
        }// end function

        public function isTouching(param1:uint) : Boolean
        {
            return (this.touching & param1) > NONE;
        }// end function

        public function justTouched(param1:uint) : Boolean
        {
            return (this.touching & param1) > NONE && (this.wasTouching & param1) <= NONE;
        }// end function

        public function hurt(param1:Number) : void
        {
            this.health = this.health - param1;
            if (this.health <= 0)
            {
                kill();
            }
            return;
        }// end function

        public static function separate(param1:FlxObject, param2:FlxObject) : Boolean
        {
            var _loc_3:* = separateX(param1, param2);
            var _loc_4:* = separateY(param1, param2);
            return _loc_3 || _loc_4;
        }// end function

        public static function separateX(param1:FlxObject, param2:FlxObject) : Boolean
        {
            var _loc_8:Number = NaN;
            var _loc_9:Number = NaN;
            var _loc_10:FlxRect = null;
            var _loc_11:FlxRect = null;
            var _loc_12:Number = NaN;
            var _loc_13:Number = NaN;
            var _loc_14:Number = NaN;
            var _loc_15:Number = NaN;
            var _loc_16:Number = NaN;
            var _loc_17:Number = NaN;
            var _loc_3:* = param1.immovable;
            var _loc_4:* = param2.immovable;
            if (_loc_3 && _loc_4)
            {
                return false;
            }
            if (param1 is FlxTilemap)
            {
                return (param1 as FlxTilemap).overlapsWithCallback(param2, separateX);
            }
            if (param2 is FlxTilemap)
            {
                return (param2 as FlxTilemap).overlapsWithCallback(param1, separateX, true);
            }
            var _loc_5:Number = 0;
            var _loc_6:* = param1.x - param1.last.x;
            var _loc_7:* = param2.x - param2.last.x;
            if (_loc_6 != _loc_7)
            {
                _loc_8 = _loc_6 > 0 ? (_loc_6) : (-_loc_6);
                _loc_9 = _loc_7 > 0 ? (_loc_7) : (-_loc_7);
                _loc_10 = new FlxRect(param1.x - (_loc_6 > 0 ? (_loc_6) : (0)), param1.last.y, param1.width + (_loc_6 > 0 ? (_loc_6) : (-_loc_6)), param1.height);
                _loc_11 = new FlxRect(param2.x - (_loc_7 > 0 ? (_loc_7) : (0)), param2.last.y, param2.width + (_loc_7 > 0 ? (_loc_7) : (-_loc_7)), param2.height);
                if (_loc_10.x + _loc_10.width > _loc_11.x && _loc_10.x < _loc_11.x + _loc_11.width && _loc_10.y + _loc_10.height > _loc_11.y && _loc_10.y < _loc_11.y + _loc_11.height)
                {
                    _loc_12 = _loc_8 + _loc_9 + OVERLAP_BIAS;
                    if (_loc_6 > _loc_7)
                    {
                        _loc_5 = param1.x + param1.width - param2.x;
                        if (_loc_5 > _loc_12 || !(param1.allowCollisions & RIGHT) || !(param2.allowCollisions & LEFT))
                        {
                            _loc_5 = 0;
                        }
                        else
                        {
                            param1.touching = param1.touching | RIGHT;
                            param2.touching = param2.touching | LEFT;
                        }
                    }
                    else if (_loc_6 < _loc_7)
                    {
                        _loc_5 = param1.x - param2.width - param2.x;
                        if (-_loc_5 > _loc_12 || !(param1.allowCollisions & LEFT) || !(param2.allowCollisions & RIGHT))
                        {
                            _loc_5 = 0;
                        }
                        else
                        {
                            param1.touching = param1.touching | LEFT;
                            param2.touching = param2.touching | RIGHT;
                        }
                    }
                }
            }
            if (_loc_5 != 0)
            {
                _loc_13 = param1.velocity.x;
                _loc_14 = param2.velocity.x;
                if (!_loc_3 && !_loc_4)
                {
                    _loc_5 = _loc_5 * 0.5;
                    param1.x = param1.x - _loc_5;
                    param2.x = param2.x + _loc_5;
                    _loc_15 = Math.sqrt(_loc_14 * _loc_14 * param2.mass / param1.mass) * (_loc_14 > 0 ? (1) : (-1));
                    _loc_16 = Math.sqrt(_loc_13 * _loc_13 * param1.mass / param2.mass) * (_loc_13 > 0 ? (1) : (-1));
                    _loc_17 = (_loc_15 + _loc_16) * 0.5;
                    _loc_15 = _loc_15 - _loc_17;
                    _loc_16 = _loc_16 - _loc_17;
                    param1.velocity.x = _loc_17 + _loc_15 * param1.elasticity;
                    param2.velocity.x = _loc_17 + _loc_16 * param2.elasticity;
                }
                else if (!_loc_3)
                {
                    param1.x = param1.x - _loc_5;
                    param1.velocity.x = _loc_14 - _loc_13 * param1.elasticity;
                }
                else if (!_loc_4)
                {
                    param2.x = param2.x + _loc_5;
                    param2.velocity.x = _loc_13 - _loc_14 * param2.elasticity;
                }
                return true;
            }
            else
            {
                return false;
            }
        }// end function

        public static function separateY(param1:FlxObject, param2:FlxObject) : Boolean
        {
            var _loc_8:Number = NaN;
            var _loc_9:Number = NaN;
            var _loc_10:FlxRect = null;
            var _loc_11:FlxRect = null;
            var _loc_12:Number = NaN;
            var _loc_13:Number = NaN;
            var _loc_14:Number = NaN;
            var _loc_15:Number = NaN;
            var _loc_16:Number = NaN;
            var _loc_17:Number = NaN;
            var _loc_3:* = param1.immovable;
            var _loc_4:* = param2.immovable;
            if (_loc_3 && _loc_4)
            {
                return false;
            }
            if (param1 is FlxTilemap)
            {
                return (param1 as FlxTilemap).overlapsWithCallback(param2, separateY);
            }
            if (param2 is FlxTilemap)
            {
                return (param2 as FlxTilemap).overlapsWithCallback(param1, separateY, true);
            }
            var _loc_5:Number = 0;
            var _loc_6:* = param1.y - param1.last.y;
            var _loc_7:* = param2.y - param2.last.y;
            if (_loc_6 != _loc_7)
            {
                _loc_8 = _loc_6 > 0 ? (_loc_6) : (-_loc_6);
                _loc_9 = _loc_7 > 0 ? (_loc_7) : (-_loc_7);
                _loc_10 = new FlxRect(param1.x, param1.y - (_loc_6 > 0 ? (_loc_6) : (0)), param1.width, param1.height + _loc_8);
                _loc_11 = new FlxRect(param2.x, param2.y - (_loc_7 > 0 ? (_loc_7) : (0)), param2.width, param2.height + _loc_9);
                if (_loc_10.x + _loc_10.width > _loc_11.x && _loc_10.x < _loc_11.x + _loc_11.width && _loc_10.y + _loc_10.height > _loc_11.y && _loc_10.y < _loc_11.y + _loc_11.height)
                {
                    _loc_12 = _loc_8 + _loc_9 + OVERLAP_BIAS;
                    if (_loc_6 > _loc_7)
                    {
                        _loc_5 = param1.y + param1.height - param2.y;
                        if (_loc_5 > _loc_12 || !(param1.allowCollisions & DOWN) || !(param2.allowCollisions & UP))
                        {
                            _loc_5 = 0;
                        }
                        else
                        {
                            param1.touching = param1.touching | DOWN;
                            param2.touching = param2.touching | UP;
                        }
                    }
                    else if (_loc_6 < _loc_7)
                    {
                        _loc_5 = param1.y - param2.height - param2.y;
                        if (-_loc_5 > _loc_12 || !(param1.allowCollisions & UP) || !(param2.allowCollisions & DOWN))
                        {
                            _loc_5 = 0;
                        }
                        else
                        {
                            param1.touching = param1.touching | UP;
                            param2.touching = param2.touching | DOWN;
                        }
                    }
                }
            }
            if (_loc_5 != 0)
            {
                _loc_13 = param1.velocity.y;
                _loc_14 = param2.velocity.y;
                if (!_loc_3 && !_loc_4)
                {
                    _loc_5 = _loc_5 * 0.5;
                    param1.y = param1.y - _loc_5;
                    param2.y = param2.y + _loc_5;
                    _loc_15 = Math.sqrt(_loc_14 * _loc_14 * param2.mass / param1.mass) * (_loc_14 > 0 ? (1) : (-1));
                    _loc_16 = Math.sqrt(_loc_13 * _loc_13 * param1.mass / param2.mass) * (_loc_13 > 0 ? (1) : (-1));
                    _loc_17 = (_loc_15 + _loc_16) * 0.5;
                    _loc_15 = _loc_15 - _loc_17;
                    _loc_16 = _loc_16 - _loc_17;
                    param1.velocity.y = _loc_17 + _loc_15 * param1.elasticity;
                    param2.velocity.y = _loc_17 + _loc_16 * param2.elasticity;
                }
                else if (!_loc_3)
                {
                    param1.y = param1.y - _loc_5;
                    param1.velocity.y = _loc_14 - _loc_13 * param1.elasticity;
                    if (param2.active && param2.moves && _loc_6 > _loc_7)
                    {
                        param1.x = param1.x + (param2.x - param2.last.x);
                    }
                }
                else if (!_loc_4)
                {
                    param2.y = param2.y + _loc_5;
                    param2.velocity.y = _loc_13 - _loc_14 * param2.elasticity;
                    if (param1.active && param1.moves && _loc_6 < _loc_7)
                    {
                        param2.x = param2.x + (param1.x - param1.last.x);
                    }
                }
                return true;
            }
            else
            {
                return false;
            }
        }// end function

    }
}
